import * as constants from './constants';
import { fromJS } from 'immutable';
import axios from 'axios';

const searchList = (data) =>({
    type:constants.SEARCH_LIST,
    data:fromJS(data),
    totalPage:Math.ceil(data.length / 10)
})

export const searchFocus = () =>({
    type:constants.SEARCH_FOCUS
})

export const searchBlur = () =>({
    type:constants.SEARCH_BLUR
})

export const changeEnter = () =>({
    type:constants.CHANGE_ENTER
})

export const changeLeave = () =>({
    type:constants.CHANGE_LEAVE
})

export const changePage = (page) =>({
    type:constants.CHANGE_PAGE,
    page
})

export const getList = () => {
	return (dispatch) => {
		axios.get('/api/headerList.json').then((res) => {
			const data = res.data;
			dispatch(searchList(data.data));
		}).catch(() => {
			console.log('error');
		})
	}
};